package com.wangtao.firstapp.adapters;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.wangtao.firstapp.R;
import com.wangtao.firstapp.modles.ShopDetailsData;

import org.xutils.common.util.DensityUtil;
import org.xutils.image.ImageOptions;
import org.xutils.x;

import java.util.List;

/**
 * ////////废弃
 * 商品详情页面-->用户晒单-->晒图 的适配器
 * Created by lanouhn on 16/9/10.
 */
public class ShopDPAdapter extends BaseAdapter {

    private Context context;
    List<ShopDetailsData.DataBean.PostListBean.PicsBean> picsBean;

    public ShopDPAdapter(Context context, List<ShopDetailsData.DataBean.PostListBean.PicsBean> picsBean) {
        this.context = context;
        this.picsBean = picsBean;
    }

    @Override
    public int getCount() {
        return picsBean.size();
    }

    @Override
    public Object getItem(int position) {
        return picsBean.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    private class ViewHolder {
        private ImageView imageView;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = View.inflate(context, R.layout.item_mygridview4, null);
            holder = new ViewHolder();
            holder.imageView = (ImageView) convertView.findViewById(R.id.iv_item_mygridview4);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        //ImageView imageView = new ImageView(context);
        ImageOptions imageOptions = new ImageOptions.Builder()
                .setSize(DensityUtil.dip2px(120), DensityUtil.dip2px(120))//图片大小
                //.setRadius(DensityUtil.dip2px(5))//ImageView圆角半径
                .setCrop(true)// 如果ImageView的大小不是定义为wrap_content, 不要crop.
                .setImageScaleType(ImageView.ScaleType.CENTER_CROP)
                .setLoadingDrawableId(R.mipmap.ic_launcher)//加载中默认显示图片
                .setFailureDrawableId(R.mipmap.ic_launcher)//加载失败后默认显示图片
                .build();

        holder.imageView.setPadding(0, 0, 0, 15);
        x.image().bind(holder.imageView, picsBean.get(position).getUrl(), imageOptions);

       // Picasso.with(context).load().into(holder.imageView);
        return convertView;


    }
}
